package org.csc.api.config;

import feign.RequestInterceptor;
import feign.RequestTemplate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

/**
 * feign拦截器
 *
 * @author zlt
 */
@Component
public class FeignInterceptorConfig implements RequestInterceptor {
    private static final Logger log = LoggerFactory.getLogger(FeignInterceptorConfig.class);

    /**
     * 使用feign client访问别的微服务时，将access_token放入参数或者header ，Authorization:Bearer xxx
     * 或者url?access_token=xxx
     */
    @Override
    public void apply(RequestTemplate template) {
        log.info("feign拦截器 --------> {}", template.method());
//            Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
//            if (authentication != null) {
//                if (authentication instanceof OAuth2Authentication) {
//                    OAuth2AuthenticationDetails details = (OAuth2AuthenticationDetails) authentication.getDetails();
//                    String access_token = details.getTokenValue();
//                    template.header("Authorization", OAuth2AccessToken.BEARER_TYPE + " " + access_token);
//                }
//            }
    }
}
